package com.yingjia.yingjiauniversity.rxbus;

import java.lang.reflect.Type;

/**
 * <订阅发布事件>
 *
 * @author: guoxiangxun
 * @date: 16-7-6 下午4:07
 * @version: v1.0
 */
public abstract class Event<T> {
    final Type type;
    final EventType eventType;
    final T data;

    protected Event() {
        this(null, EventType.DATA);
    }


    public Event(EventType eventType) {

        this(null, eventType);
    }

    public Event(T data) {
        this(data, EventType.DATA);
    }

    public Event(T data, EventType eventType) {
        this.data = data;
        Type superClass = getClass().getGenericSuperclass();
        if (superClass instanceof Class<?>) { // sanity check, should never happen
            throw new IllegalArgumentException("Internal error: TypeReference constructed without actual type information");
        }
        this.type = superClass;
        this.eventType = eventType;
    }

    public T getData() {
        return data;
    }

    public String getTopic() {
        return eventType.toString() + "_" + type.toString();
    }

    public Type getType() {
        return type;
    }
}
